﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;

public class LoadSongList : MonoBehaviour
{
    private string[] songList;//读取到的每个谱面文件完整路径
    private string songText;//带后缀名谱面名字
    private GameObject songButton;
    public GameObject song;
    // Start is called before the first frame update
    void Start()
    {
#if UNITY_ANDROID
        //songList = Directory.GetFiles(Application.persistentDataPath + "/sheet/", "*.txt");//安卓11以后data普通用户不root无权限自行写入 考虑换存储路径
        songList = Directory.GetFiles("/storage/emulated/0/TheFinalMugDemo/sheet/", "*.txt");
#else
        songList = Directory.GetFiles(Application.dataPath + "/Resources/sheet/", "*.txt");
#endif
        for (int i = 0;i<songList.Length;i++)
        {
#if UNITY_ANDROID
            //songText = songList[i].Replace(Application.persistentDataPath + "/sheet/", "");//安卓11以后data普通用户不root无权限自行写入 考虑换存储路径
            songText = songList[i].Replace("/storage/emulated/0/TheFinalMugDemo/sheet/", "");
#else
            songText = songList[i].Replace(Application.dataPath + "/Resources/sheet/", "");
#endif
            songButton = Instantiate(song, GameObject.Find("Canvas/Panel/Panel2").GetComponent<Transform>());
            songButton.GetComponent<songButton>().songName = songText;
            songButton.GetComponentInChildren<Text>().text = songButton.GetComponent<songButton>().songName.Replace(".txt","");
        }
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
